package factorytest.iflytek.com.einkiflytekfactorytest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import factorytest.iflytek.com.einkiflytekfactorytest.config.EinkProperty;
import factorytest.iflytek.com.einkiflytekfactorytest.utils.DebugLog;
import factorytest.iflytek.com.einkiflytekfactorytest.common.FTUtils;
import factorytest.iflytek.com.einkiflytekfactorytest.utils.executor.AppExecutors;

/**
 * Created by sst on 2018/5/30.
 */

public class BootCompletedReceiver extends BroadcastReceiver implements Runnable {

    private final static String TAG = "BootCompletedReceiver";
    @Override
    public void onReceive(Context context, Intent intent) {
        final String action = intent.getAction();

        DebugLog.e( "~~~~~ Congratulations: We receive BootCompletedReceiver");

        if (action != null && action.equals(Intent.ACTION_BOOT_COMPLETED)) {

            AppExecutors.runOnIoThread(this);
        }
    }

    @Override
    public void run() {

        final boolean isPvRoEinkFTDone = EinkProperty.isPvRoEinkFTDone();
        final boolean isFTPassed = FTUtils.isFTPassed();
        DebugLog.e( "~~~~~ Congratulations: We receive BootCompletedReceiver isPvRoEinkFTDone = "
                + isPvRoEinkFTDone
                + ", isFTPassed = " + isFTPassed);

//        if (isPvRoEinkFTDone && isFTPassed) {
//            DebugLog.e(" PvRoEinkFTDone and FTPassed, return directly.");
//            return;
//        }
        if (isPvRoEinkFTDone) {
            return;
        }

        FTUtils.startMainActivity(RootApplication.getContext());

    }
}
